﻿
Imports System.IO
<Serializable()> Public Class OnSiteMetData
    Implements ICloneable

    Private m_title As New LocaleWeatherTitleData
    Private m_localeConcourse As New LocaleWeatherDataConcourse
    ''' <summary>
    ''' 现站数据的标题
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Title() As LocaleWeatherTitleData
        Get
            Return m_title
        End Get
        Set(ByVal value As LocaleWeatherTitleData)
            m_title = value
        End Set
    End Property
    Property LocaleConcourse() As LocaleWeatherDataConcourse
        Get
            Return m_localeConcourse
        End Get
        Set(ByVal value As LocaleWeatherDataConcourse)
            m_localeConcourse = value
        End Set
    End Property

    Public Sub ImportData(ByVal FileName As String)
        Dim f_DistanceTerraHeight As String = ""
        Dim f_LevelWindVane As String = ""
        Dim f_ApeakWindSpeed As String = ""
        Dim f_Temperature As String = ""
        Dim f_WindVane As String = ""
        Dim f_WindSpeed As String = ""

        Dim msg As Integer = 0
        Dim msgerror As Boolean = False
        Dim a1 As Integer = 0
        Dim count As Integer = 0
        Dim p As Integer = 0
        Dim w1 As Integer = 0
        Dim w2 As Integer = 0
        Dim d As Integer = 1
        Dim tr As Boolean = False
        Dim Result As DialogResult
        Dim title As String = "*** EOH: END OF ON-SITE QA HEADERS"

        Dim tt As String = "       "
        Dim b As Integer = 0
        If FileName <> "" Then

            Do Until EOF(1)
                Dim strline As String = LineInput(1)
                msg += 1
                If msg = 1 Then
                    If StringHandle.FileType(strline) = 2 Then
                        msgerror = True
                        StringHandle.L_openFile = 1
                    Else
                        msgerror = False
                        Result = MessageBox.Show("你选择的文件格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
                        If Result = Windows.Forms.DialogResult.OK Then
                            Exit Do
                        End If
                    End If
                End If


                count += 1
                If count = 3 Then
                    Me.m_title.WeatherName = StringHandle.GetString(strline, 3).ToString.Remove(7, 4) '.PadRight(7)

                ElseIf count = 4 Then
                    'Me.m_title.StartTime = StringHandle.GetString(strline, 3)
                    'Me.txtStartTime.Text = Me.m_title.StartTime
                    'Me.m_title.EndTime = StringHandle.GetString(strline, 5)
                    'Me.txtEndTime.Text = Me.m_title.EndTime
                ElseIf count = 5 Then
                    'Me.m_title.WeatherID = StringHandle.GetString(strline, 3)
                    'Me.txtID.Text = Me.m_title.WeatherID
                    'Me.m_title.Longitude = StringHandle.GetString(strline, 4)
                    'Me.txtLongitude.Text = Me.m_title.Longitude
                    'Me.m_title.Latitude = StringHandle.GetString(strline, 5)
                    'Me.txtLatitude.Text = Me.m_title.Latitude

                    Dim one As String = ""
                    Dim two As String = ""
                    one = StringHandle.GetString(strline, 4)
                    two = StringHandle.GetString(strline, 5)


                    If StringHandle.GetLastlyChar(one) = True Then
                        m_title.Longitude = StringHandle.GetString(strline, 4)
                    ElseIf StringHandle.GetLastlyChar(one) = False Then
                        m_title.Latitude = StringHandle.GetString(strline, 4)
                    End If


                    If StringHandle.GetLastlyChar(two) = True Then
                        m_title.Longitude = StringHandle.GetString(strline, 5)
                    ElseIf StringHandle.GetLastlyChar(two) = False Then
                        m_title.Latitude = StringHandle.GetString(strline, 5)
                    End If
                End If

                If count <= 18 Then
                    Me.m_title.SumString += strline + vbCrLf
                End If
                If strline = title Then
                    tr = True
                End If
                If tr = True Then
                    p = p + 1
                End If
                If p > 1 Then

                    If strline.StartsWith(tt) = False Then
                        If d > 1 Then
                            Me.m_localeConcourse.CountSumTier = Me.m_localeConcourse.CountSumTier - 1
                            Me.m_localeConcourse.CountSumTier += d
                        End If

                        d = 1
                        w2 = 0
                        ReDim Preserve m_localeConcourse.ArrLocaleWeatherData(w1)
                        m_localeConcourse.ArrLocaleWeatherData(w1) = New LocaleWeatherData
                        'm_localeConcourse.ArrLocaleWeatherData(w1).Day = StringHandle.GetString(strline, 1)
                        'm_localeConcourse.ArrLocaleWeatherData(w1).Month = StringHandle.GetString(strline, 2)
                        'm_localeConcourse.ArrLocaleWeatherData(w1).Year = StringHandle.GetString(strline, 3)
                        'm_localeConcourse.ArrLocaleWeatherData(w1).Time = StringHandle.GetString(strline, 4)

                        If StringHandle.GetString(strline, 1).Length = 1 Then
                            m_localeConcourse.ArrLocaleWeatherData(w1).Day = "0" & StringHandle.GetString(strline, 1)
                        Else
                            m_localeConcourse.ArrLocaleWeatherData(w1).Day = StringHandle.GetString(strline, 1)
                        End If
                        If StringHandle.GetString(strline, 2).Length = 1 Then
                            m_localeConcourse.ArrLocaleWeatherData(w1).Month = "0" & StringHandle.GetString(strline, 2)
                        Else
                            m_localeConcourse.ArrLocaleWeatherData(w1).Month = StringHandle.GetString(strline, 2)
                        End If

                        If StringHandle.GetString(strline, 3).Length = 2 Then
                            'If CInt(StringHandle.GetString(strline, 3)) > 50 Then
                            '    m_localeConcourse.ArrLocaleWeatherData(w1).Year = "19" & StringHandle.GetString(strline, 3)
                            'Else
                            '    m_localeConcourse.ArrLocaleWeatherData(w1).Year = "20" & StringHandle.GetString(strline, 3)
                            'End If
                            If CInt(StringHandle.GetString(strline, 3)) > 50 Then
                                m_localeConcourse.ArrLocaleWeatherData(w1).Year = StringHandle.GetString(strline, 3)
                            Else
                                m_localeConcourse.ArrLocaleWeatherData(w1).Year = StringHandle.GetString(strline, 3)
                            End If
                        Else
                            m_localeConcourse.ArrLocaleWeatherData(w1).Year = StringHandle.GetString(strline, 3)
                        End If

                        If CInt(StringHandle.GetString(strline, 4)) < 10 Then
                            m_localeConcourse.ArrLocaleWeatherData(w1).Time = "0" & StringHandle.GetString(strline, 4)
                        Else
                            m_localeConcourse.ArrLocaleWeatherData(w1).Time = StringHandle.GetString(strline, 4)
                        End If

                        ReDim Preserve m_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2)
                        m_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2) = New LocaleWeatherTierData

                        f_DistanceTerraHeight = Mid(strline, 12, 10)
                        f_LevelWindVane = Mid(strline, 22, 6)
                        f_ApeakWindSpeed = Mid(strline, 28, 8)
                        f_Temperature = Mid(strline, 36, 7)
                        f_WindVane = Mid(strline, 43, 8)
                        f_WindSpeed = Mid(strline, 51, 8)

                        m_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).DistanceTerraHeight = f_DistanceTerraHeight.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).LevelWindVane = f_LevelWindVane.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).ApeakWindSpeed = f_ApeakWindSpeed.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).Temperature = f_Temperature.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).WindVane = f_WindVane.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).WindSpeed = f_WindSpeed.Trim()


                        'm_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).DistanceTerraHeight = StringHandle.GetString(strline, 5)
                        'm_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).LevelWindVane = StringHandle.GetString(strline, 6)
                        'm_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).ApeakWindSpeed = StringHandle.GetString(strline, 7)
                        'm_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).Temperature = StringHandle.GetString(strline, 8)
                        'm_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).WindVane = StringHandle.GetString(strline, 9)
                        'm_localeConcourse.ArrLocaleWeatherData(w1).ArrTierData(w2).WindSpeed = StringHandle.GetString(strline, 10)
                        a1 = 1
                    ElseIf strline.StartsWith(tt) = True Then

                        d += 1
                        w2 += 1
                        ReDim Preserve m_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2)
                        m_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2) = New LocaleWeatherTierData

                        f_DistanceTerraHeight = Mid(strline, 1, 21)
                        f_LevelWindVane = Mid(strline, 22, 6)
                        f_ApeakWindSpeed = Mid(strline, 28, 8)
                        f_Temperature = Mid(strline, 36, 7)
                        f_WindVane = Mid(strline, 43, 8)
                        f_WindSpeed = Mid(strline, 51, 8)

                        m_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).DistanceTerraHeight = f_DistanceTerraHeight.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).LevelWindVane = f_LevelWindVane.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).ApeakWindSpeed = f_ApeakWindSpeed.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).Temperature = f_Temperature.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).WindVane = f_WindVane.Trim()
                        m_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).WindSpeed = f_WindSpeed.Trim()

                        'm_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).DistanceTerraHeight = StringHandle.GetString(strline, 1)
                        'm_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).LevelWindVane = StringHandle.GetString(strline, 2)
                        'm_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).ApeakWindSpeed = StringHandle.GetString(strline, 3)
                        'm_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).Temperature = StringHandle.GetString(strline, 4)
                        'm_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).WindVane = StringHandle.GetString(strline, 5)
                        'm_localeConcourse.ArrLocaleWeatherData(w1 - 1).ArrTierData(w2).WindSpeed = StringHandle.GetString(strline, 6)
                        a1 = 0

                    End If

                    If a1 = 1 Then
                        w1 += 1

                    End If
                End If
            Loop
            If msgerror = True Then
                Me.m_localeConcourse.CountTierData = Me.m_localeConcourse.ArrLocaleWeatherData(0).ArrTierData.Length
                Dim sl As Integer = Me.m_localeConcourse.ArrLocaleWeatherData.Length - 1
            End If
            FileClose(1)
        End If
    End Sub
    Public Sub ExportData(ByVal SaveFileName As String)
        Dim sStart As String = ""
        Dim sEnd As String = ""
        Dim sDate As String = ""
        Dim sPlace As String = ""

        Dim str As String = ""
        Dim month As String = ""
        Dim time As String = ""

        Dim sw As StreamWriter
        sw = New StreamWriter(SaveFileName)
        Dim L As Integer = Me.m_localeConcourse.ArrLocaleWeatherData.Length - 1

        sw.Write(Me.m_title.TitleTop)

        Me.m_title.StartTime = Me.m_localeConcourse.ArrLocaleWeatherData(0).Year & "/" & Me.m_localeConcourse.ArrLocaleWeatherData(0).Month & "/" & Me.m_localeConcourse.ArrLocaleWeatherData(0).Day
        Me.m_title.EndTime = Me.m_localeConcourse.ArrLocaleWeatherData(L).Year & "/" & Me.m_localeConcourse.ArrLocaleWeatherData(L).Month & "/" & Me.m_localeConcourse.ArrLocaleWeatherData(L).Day
        sDate = Me.m_title.StartTime & " TO " & Me.m_title.EndTime

        sw.Write(sDate)
        sPlace = Me.m_title.TitleMiddlePlace & Me.m_title.Longitude & " " & Me.m_title.Latitude
        sw.Write(sPlace)
        sw.Write(Me.m_title.TitleBottomOne)
        sw.Write(Me.m_title.TitleBottomTwo)
        For i As Integer = 0 To m_localeConcourse.ArrLocaleWeatherData.Length - 1
            str = ""
            str = CInt(m_localeConcourse.ArrLocaleWeatherData(i).Day)
            str = str.PadLeft(2)
            month = CInt(m_localeConcourse.ArrLocaleWeatherData(i).Month)
            str += month.PadLeft(3)
            ' str += m_localeConcourse.ArrLocaleWeatherData(i).Month.ToString.PadLeft(3)
            If m_localeConcourse.ArrLocaleWeatherData(i).Year.Length = 4 Then
                str += Mid(m_localeConcourse.ArrLocaleWeatherData(i).Year, 3, 2).PadLeft(3)
            Else
                str += m_localeConcourse.ArrLocaleWeatherData(i).Year.PadLeft(3)
            End If
            ' str += m_localeConcourse.ArrLocaleWeatherData(i).Year.ToString.PadLeft(3)
            time = CInt(m_localeConcourse.ArrLocaleWeatherData(i).Time)
            str += time.PadLeft(3)
            ' str += m_localeConcourse.ArrLocaleWeatherData(i).Time.ToString.PadLeft(3)
            For j As Integer = 0 To m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData.Length - 1
                If j = 0 Then
                    If m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).DistanceTerraHeight = Nothing Then
                        str += CStr(9999).ToString.PadLeft(10)
                    Else
                        str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).DistanceTerraHeight.ToString.PadLeft(10)
                    End If
                    'str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).DistanceTerraHeight.ToString.PadLeft(10)

                ElseIf j > 0 Then

                    'str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).DistanceTerraHeight.ToString.PadLeft(21)
                    If m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).DistanceTerraHeight = Nothing Then
                        str = ""
                        str += CStr(9999).ToString.PadLeft(10)
                    Else
                        str = ""
                        str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).DistanceTerraHeight.ToString.PadLeft(21)
                    End If
                End If
                If m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).LevelWindVane = Nothing Then
                    str += CStr(-99).ToString.PadLeft(6)
                Else
                    str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).LevelWindVane.ToString.PadLeft(6)
                End If
                If m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).ApeakWindSpeed = Nothing Then
                    str += CStr(99).ToString.PadLeft(8)
                Else
                    str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).ApeakWindSpeed.ToString.PadLeft(8)
                End If
                If m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).Temperature = Nothing Then
                    str += CStr(-99).ToString.PadLeft(7)
                Else
                    str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).Temperature.ToString.PadLeft(7)
                End If

                If m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).WindVane = Nothing Then

                    str += CStr(-999).ToString.PadLeft(8)
                Else
                    str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).WindVane.ToString.PadLeft(8)
                End If

                If m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).WindSpeed = Nothing Then

                    str += CStr(-999).ToString.PadLeft(8)
                Else
                    str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).WindSpeed.ToString.PadLeft(8)
                End If

                'str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).LevelWindVane.ToString.PadLeft(6)
                'str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).ApeakWindSpeed.ToString.PadLeft(8)
                'str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).Temperature.ToString.PadLeft(7)
                'str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).WindVane.ToString.PadLeft(8)
                'str += m_localeConcourse.ArrLocaleWeatherData(i).ArrTierData(j).WindSpeed.ToString.PadLeft(8)
                sw.WriteLine(str)
            Next
            ' sw.WriteLine(str)
        Next

        sw.Close()
        sw.Dispose()
    End Sub

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim objCopy As New OnSiteMetData
        objCopy.m_localeConcourse = Me.m_localeConcourse.Clone
        objCopy.m_title = Me.m_title.Clone
        Return objCopy
    End Function
End Class
